import { throttle } from '../../tool/util'
Component({
  externalClasses: ["content-box", 'set-bnt'],
  /**
   * 组件的属性列表
   */
  properties: {
    path: {
      type: String,
      value: ''
    },
    showRightClons:{ //  弹窗右侧是否显示关闭按钮
      type: Boolean,
      value: false
    },
    title: { // 标题 可控制是否显示和 标题内容
      type: Object,
      value: '确定'
    },
    content: { // 显示内容
      type: String,
      value: ''
    },
    text: { // 显示内容
      type: String,
      value: ''
    },
    bnt: { // 控制按钮是否显示
      type: Object,
      value: {
        cancel: {
          txt: '取消'
        },
        ok: {
          txt: '确定'
        },
        openSetting: {
          is: true,
        }
      }
    },
    width: {
      type: String,
      value: '100%'
    },
    height: {
      type: String,
      value: '30vh'
    }
  },

  /**
   * 组件的初始数据
   */
  data: {
    show: false,
    load: '',
  },

  created () {
  },
  /**
 * 组件的方法列表
 */
  methods: {
    // 节流
    throttle (fn, gapTime = 200) {
      if (gapTime == null || gapTime == undefined)
      {
        gapTime = 1500
      }
      let _lastTime = null
      return function () {
        let _nowTime = +new Date()
        if (_nowTime - _lastTime > gapTime || !_lastTime)
        {
          fn()
          _lastTime = _nowTime
        }
      }
    },
    // 关闭
    rightClons:throttle(function () {
      this.triggerEvent('rightClons', this.properties.bnt.key)
    }),
    // 取消
    cancelfun: throttle(function () {
      this.triggerEvent('cancel', this.properties.bnt.key)
      // let load = this.selectComponent('#load')
      // load.openShow()
    }),    // 确认
    okfun: throttle(function () {
      this.triggerEvent('ok', this.properties.bnt.key)
      // let load = this.selectComponent('#load')
      // load.openShow()
    }
    ),
  }
})
